package org.xiji.mediator;

import java.util.ArrayList;
import java.util.List;

public class MediatorImpl implements Mediator{
    /**
     * 定义集合，用于存储所有的同事对象
     */
    List<User> users = new ArrayList<>();
    /**
     *添加用户
     */
    @Override
    public void register(User user) {
        users.add(user);
    }

    /**
     * 转发信息
     */
    @Override
    public void sendMessage(String msg, SendAndReceiveContain sendAndReceiveContain) {

        for (User user : users) {

                if (user.name.equals(sendAndReceiveContain.receiver.name)) {
                    //转发信息
                    System.out.println("惜己"+"把"+sendAndReceiveContain.send.name+msg+"带给"+sendAndReceiveContain.receiver.name);
                    user.receive(msg,sendAndReceiveContain);

                }



        }

    }
}
